package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    @GetMapping("/channel/{c1Id}")
    @Operation(summary = "首页数据的展示")
    public Result channel(@PathVariable(value = "c1Id") Long c1Id) {
        List<Map<String, Object>> map = searchService.channel(c1Id);
        return Result.ok(map);
    }
    //Request URL: http://localhost:8500/api/search/albumInfo
    @PostMapping
    @Operation(summary = "专辑搜索")
    public Result search(@RequestBody AlbumIndexQuery albumIndexQuery){
        AlbumSearchResponseVo albumSearchResponseVo = searchService.search(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }
    //path: "/api/search/albumInfo/completeSuggest/%E9%9F%B3%E4%B9%90"
    @GetMapping("/completeSuggest/{content}")
    @Operation(summary = "搜索建议(提示词)")
    public Result completeSuggest(@PathVariable("content") String content){
        Set<String> set = searchService.completeSuggest(content);
        return Result.ok(set);
    }

}

